define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {

    var Controller = {
        index: function () {
            Table.api.init({
                extend: {
                    export_log_url: 'dashboard/serviceexport',//导出路径
                }
            });
            tables_list=[];
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'dashboard/gcbl',
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_name:r.factory_name,
                                    san:r.san,
                                    qi:r.qi,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.san+'%</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.qi+'%</td>';

                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
//导出
            $(document).on("click", ".btn-export-log", function () {
                //var ids = Table.api.selectedids(table);

                let startTime = $('#gcpaihangstart_time').val();
                let endTime = $('#gcpaihangend_time').val();


                Layer.confirm("<form action='" + Fast.api.fixurl($.fn.bootstrapTable.defaults.extend.export_log_url) + "' method='post' target='_blank'>" +
                    "<input type='hidden' name='startTime' value='' />" +
                    "<input type='hidden' name='endTime' value='' />" +
                    "<input type='hidden' name='filter' >" +
                    "<input type='hidden' name='op'>" +
                    "<input type='hidden' name='search'>" +
                    "<input type='hidden' name='columns'></form>", {

                    //title: '导出数据',
                    //btn: ["选中项11(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],

                    success: function (layero, index) {

                        console.log(layero);
                       // var options = table.bootstrapTable('getOptions');



                        $("input[name=startTime]", layero).val(startTime);
                        $("input[name=endTime]", layero).val(endTime);

                        $("form", layero).submit();
                        layer.closeAll('dialog');
                        return false;
                    },

                });
            });

            getListtbody_gc();
            function getConfig_gc(){
                $.ajax({
                    url: 'dashboard/gcblgc',
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    san:r.san,
                                    qi:r.qi,
                                }
                            );
                        });
                        getListtbody_gc();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody_gc(){
                var html='';
                console.log(7777,Config.factory_work_name_arr_thr);
                Config.factory_work_name_arr_thr.forEach((r,index)=>{
                    console.log(232+"))___");
                    var pieChart = Echarts.init(document.getElementById('pie-chart-'+r.key), 'walden');
                    var option = {
                        tooltip: {
                            trigger: 'item',
                            formatter: '{a} <br/>{b}: {c} ({d}%)'
                        },
                        legend: {
                            orient: 'vertical',

                            left: 10,
                            data: r.factory_work_name_arr,
                        },
                        series: [
                            {
                                name: '问题数量',
                                type: 'pie',
                                radius: ['50%', '70%'],
                                padding:20,
                                avoidLabelOverlap: false,
                                label: {
                                    normal: {
                                        show: false,
                                        position: 'center'
                                    },
                                    emphasis: {
                                        show: true,
                                        textStyle: {
                                            fontSize: '30',
                                            fontWeight: 'bold'
                                        }
                                    }
                                },
                                labelLine: {
                                    normal: {
                                        show: false
                                    }
                                },
                                data: r.factory_work_sum_arr
                            }
                        ]
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    pieChart.setOption(option);
                });
                $('.lyj_tbody').html(html);
            }




            require(['bootstrap-datetimepicker'], function () {
                var options = {
                    format: 'Y-M-D',
                    icons: {
                        time: 'fa fa-clock-o',
                        date: 'fa fa-calendar',
                        up: 'fa fa-chevron-up',
                        down: 'fa fa-chevron-down',
                        previous: 'fa fa-chevron-left',
                        next: 'fa fa-chevron-right',
                        today: 'fa fa-history',
                        clear: 'fa fa-trash',
                        close: 'fa fa-remove'
                    },
                    showTodayButton: true,
                    showClose: true
                };
                $('.datetimepickerY').parent().css('position', 'relative');
                $('.datetimepickerY').datetimepicker(options);
                $('.datetimepickerY1').parent().css('position', 'relative');
                $('.datetimepickerY1').datetimepicker(options);
            });
            $("#startDate").on("dp.update", function(){
                var that = this;
                $("select[name='quarter']").val('');
                $("select[name='month']").val('');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    params.year = $(that).val(); // 值
                    console.log(params);
                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;
            });
            $("#endDate").on("dp.update", function(){
                var that = this;
                $("select[name='quarter']").val('');
                $("select[name='month']").val('');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    params.year = $(that).val(); // 值
                    console.log(params);
                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;
            });

            // 基于准备好的dom，初始化echarts实例
            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '',
                    subtext: ''
                },
                color: [
                    "#18d1b1",
                    "#3fb1e3",
                    "#626c91",
                    "#a0a7e6",
                    "#c4ebad",
                    "#96dee8"
                ],
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: [__('新增工单总量'),__('多次维修工单')]
                },
                toolbox: {
                    show: false,
                    feature: {
                        magicType: {show: true, type: ['stack', 'tiled']},
                        saveAsImage: {show: true}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Config.column
                },
                yAxis: {},
                grid: [{
                    left: '20',
                    top: '20',
                    right: '40',
                    bottom: 30
                },{
                    left: '20',
                    top: '20',
                    right: '40',
                    bottom: 30
                }],
                series: [{
                    name: __('新增工单总量'),
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Config.userdata
                },{
                name: __('多次维修工单'),
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                    normal: {}
                },
                lineStyle: {
                    normal: {
                        width: 1.5
                    }
                },
                data: Config.twouserdata
            }]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);


            // 基于准备好的dom，初始化echarts实例
            var myChartNow = Echarts.init(document.getElementById('echart-now'), 'walden');

            // 指定图表的配置项和数据
            var optionnow = {
                title: {
                    text: '',
                    subtext: ''
                },
                color: [
                    "#18d1b1",
                    "#3fb1e3",
                    "#626c91",
                    "#a0a7e6",
                    "#c4ebad",
                    "#96dee8"
                ],
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: [__('知识数'),__('访问量')]
                },
                toolbox: {
                    show: false,
                    feature: {
                        magicType: {show: true, type: ['stack', 'tiled']},
                        saveAsImage: {show: true}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Config.knowcolumn
                },
                yAxis: {},
                grid: [{
                    left: '40',
                    top: '20',
                    right: '40',
                    bottom: 30
                },{
                    left: '40',
                    top: '20',
                    right: '40',
                    bottom: 30
                }],
                series: [{
                    name: __('知识数'),
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Config.knowdata
                },{
                    name: __('访问量'),
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Config.knowlogdata
                }]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChartNow.setOption(optionnow);


            $(window).resize(function () {
                myChart.resize();
            });

            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    myChart.resize();
                }, 0);
            });
            $(window).resize(function () {
                myChartNow.resize();
            });

            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    myChartNow.resize();
                }, 0);
            });
// 使用刚指定的配置项和数据显示图表。
            //pieChart.setOption(option);

          /*  var pieChart = Echarts.init(document.getElementById('pie-chart'), 'walden');
            var optionqq = {
                tooltip: {
                    trigger: 'item',
                    formatter: '{a} <br/>{b}: {c} ({d}%)'
                },
                legend: {
                    orient: 'vertical',
                    left: 10,
                    data: Config.factory_work_name_arr
                },
                series: [
                    {
                        name: '工单数量',
                        type: 'pie',
                        radius: ['50%', '70%'],
                        avoidLabelOverlap: false,
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: '30',
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data: Config.factory_work_sum_arr
                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            pieChart.setOption(optionqq);*/
            // 使用刚指定的配置项和数据显示图表。
            //pieChart.setOption(option);

            var pieChartT = Echarts.init(document.getElementById('pie-chart-two'), 'walden');
            var optionT = {
                tooltip: {
                    trigger: 'item',
                    formatter: '{a} <br/>{b}: {c} ({d}%)'
                },
                legend: {
                    orient: 'vertical',
                    left: 10,
                    data: Config.factory_work_name_arr_two
                },
                series: [
                    {
                        name: '工单数量',
                        type: 'pie',
                        radius: ['50%', '70%'],
                        avoidLabelOverlap: false,
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: '30',
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data: Config.factory_work_sum_arr_two
                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            pieChartT.setOption(optionT);
            $(window).resize(function () {
                pieChartT.resize();
            });

            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    pieChartT.resize();
                }, 0);
            });
            $(window).resize(function () {
                pieChart.resize();
            });

            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    pieChart.resize();
                }, 0);
            });
        }
    };

    return Controller;
});
